<template>
	<view class="padb20">
		<stop isBack>
			<view slot="content">物资入库</view>
		</stop>
		<view class="lh2 bcf pad2 bdtso mart3">
			<view class="list-style-2 flrc">
				<view class="flex1">入库单信息</view>
			</view>
			<view class="lh2 bcf pad2 mart3">
				<sentity label="调出仓库" model="Store" placeholder="请选择" v-model="en.storeOut"></sentity>
			</view>
			<view class="lh2 bcf pad2 mart3">
				<sentity label="接收仓库" model="Store" placeholder="请选择" v-model="en.storeIn"></sentity>
			</view>
			<view class="lh2 bcf pad2 bdtda">
				<stextarea label="备注" placeholder="可选备注信息" v-model="en.info"></stextarea>
			</view>
		</view>
		
		
		<view class="lh2 bcf pad2 bdtso mart3">
			<view class="list-style-2 flrc">
				<view class="flex1">选择物资</view>
				<!-- <view class="cu-btn line-green round" @tap="showSelect" >添加</view> -->
				<view class="cu-btn line-green round marr2" @tap="scanStoreItem" >
					<text class="cuIcon-scan"></text>
					<ripple></ripple>
				</view>
				<view class="cu-btn line-green round" @tap="showSelect" >
					添加
					<ripple></ripple>
				</view>
			</view>
			<!-- 显示选择的物资 -->
			<view class="flcc bdso mart3" v-for="item,index in en.items"
			v-if="isbool(en.items)">
				<store-item class="w100 bc13 pad1" :iri="item"></store-item>
				<view class="w100 bdtdo bc13">
					<stext label="数量" placeholder="请输入数量" v-model="nums[index]"></stext>
				</view>
			</view>
			<view class="pad3" v-if="en.items.length === 0">
				<view class="bdda tac pad5">未选择任何数据</view>
			</view>
		</view>
		<view class="lh2 bcf pad2 bdtso pos-f l0 r0 b0">
			<view class="tac pad2 line-green round cu-btn lg w100 mart5" @tap="submit">
				<view>提交</view>
				<ripple></ripple>
			</view>
		</view>
		<!-- <loading :loading="myIsLoading"></loading> -->
		<store-item-selector :show="showSelectList" @onSelect="selectStoreItem"></store-item-selector>
	</view>
</template>

<script>
	import StoreItem from '../../templete/store/store_item.vue'
	import StoreItemSelector from '../../templete/store/store_item_selector.vue'
	export default {
		components:{StoreItem,StoreItemSelector},
		data() {
			return {
				id:"",
				showSelectList:true,
				showSelected:true,
				selectedStoreItem:{
					id:'',
					code:'',
					iri:''
				},
				en:{
					typeIn:'/api_/store_log_types/1',
					storeIn:'',
					typeOut:'/api_/store_log_types/2',
					storeOut:'',
					tips:'',
					items:[]
				},
				nums:[]
			}
		},
		methods: {
			showSelect(){
				this.showSelectList = Math.random()
			},
			selectStoreItem(val){
				this.log(val)
				this.en.items.push(val.iri)
				this.nums.push("1")
				// this.selectedStoreItem.iri=val
			},
			scanStoreItem(){
				this.$dev.scan(info=>{
					this.$api.getRes(info,en=>{
						if(this.$com.isTrue(en)){
							this.en.items.push(info)
							this.nums.push("1")
						}
					})
				},(err)=>{
					
				})
			},
			submit(){
				this.log(this.en)
				//检查数据
				if(this.isnull(this.en.storeOut)){this.$com.showToast('请选择调出仓库');return;}
				if(this.isnull(this.en.storeIn)){this.$com.showToast('请选择拨入仓库');return;}
				if(this.isnull(this.en.items)){this.$com.showToast('没有选择任何物资');return;}
				this.$api.post("/api/storeIns/exchange",{
					typeIn:this.en.typeIn,
					typeOut:this.en.typeOut,
					storeOut:this.en.storeOut,
					storeIn:this.en.storeIn,
					tips:this.en.tips,
					items:this.en.items,
					nums:this.nums,
				},(res)=>{
					this.log(res)
					if(res.s == 1){
						this.goback()
					}
				})
			}
		},
		onLoad(option) {
			this.clearLoading()
			this.id = option.id
		},
		watch:{
			nums(va){
				this.log(va)
			}
		}
	}
</script>

<style>

</style>
